﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KorleBu.Application_Classes
{
    /// <summary>
    /// Represents a User and their information after Login.
    /// This object is to be used globally and persist throughout all pages.
    /// </summary>
    public class User
    {
        #region class state variables
        //TODO:  lblValidate, lblLastAction ?

        /// <summary>
        /// Represents a user's ID in the User table in the database.
        /// </summary>
        private int userId;
        /// <summary>
        /// Represents a user's username in the User table in the database.
        /// </summary>
        private string userName;
        /// <summary>
        /// Represents a user's first name in the User table in the database.
        /// </summary>
        private string firstName;
        /// <summary>
        /// Represents a user's last name in the User table in the database.
        /// </summary>
        private string lastName;
        /// <summary>
        /// Represents a user's password in the User table in the database.
        /// </summary>
        private string password;
        /// <summary>
        /// Represents a user's password hint in the User table in the database.
        /// </summary>
        private string passwordHint;
        /// <summary>
        /// Represents a user's email address in the User table in the database, this value can be null.
        /// </summary>
        private string email;
        /// <summary>
        /// Represents whether the user has Admin rights.
        /// </summary>
        private bool isAdmin;
        /// <summary>
        /// Represents whether the user has CEO rights.
        /// </summary>
        private bool isCEO;
        /// <summary>
        /// Represents whether the user has General Manager rights.
        /// </summary>
        private bool isGeneralManager;
        /// <summary>
        /// Represents whether the user has Store Manager rights.
        /// </summary>
        private bool isStoreManager;
        /// <summary>
        /// Represents whether the user has Store Keeper rights.
        /// </summary>
        private bool isStoreKeeper;
        /// <summary>
        /// Represents whether the user has Subunit Clerk rights.
        /// </summary>
        private bool isSubUnitClerk;
        /// <summary>
        /// Represents whether the user has Accounting rights.
        /// </summary>
        private bool isAccounting;
        /// <summary>
        /// Represents whether the user has Procurement rights.
        /// </summary>
        private bool isProcurement;
        /// <summary>
        /// Represents whether this user's account is still active or not.
        /// </summary>
        private int statusId;
        /// <summary>
        /// Represents the logged in User's session ID 
        /// </summary>
        private string sessionId;
        /// <summary>
        /// 
        /// </summary>
        private int storeId;

        #endregion

        #region constructors

        /// <summary>
        /// Constructs a User object setting all of the values to empty.
        /// </summary>
        public User()
        {
            //userId = 0;
            //userName = null;
            //firstName = null;
            //lastName = null;
            //password = null;
            //passwordHint = null;
            //email = null;
            //isAdmin = false;
            //isCEO = false;
            //isGeneralManager = false;
            //isStoreManager = false;
            //isStoreKeeper = false;
            //isSubUnitClerk = false;
            //isAccounting = false;
            //isProcurement = false;
            //statusId = 0;
            //sessionId = null;
            //storeId = 0;
        }

        /// <summary>
        /// Constructs a User object setting all of the values to the parameters sent in.
        /// There are default values of null for strings, false for bool, 0 for uId, and 1 for statusId for where there are no parameters sent in.
        /// </summary>
        /// <param name="uId">int userID</param>
        /// <param name="uName">string username</param>
        /// <param name="fName">string first name</param>
        /// <param name="lName">string last name</param>
        /// <param name="pswd">string password</param>
        /// <param name="pswdHint">string password hint</param>
        /// <param name="email">string email</param>
        /// <param name="admin">bool admin role</param>
        /// <param name="genMgr">bool general manager role</param>
        /// <param name="storeMgr">bool store manager role</param>
        /// <param name="storeKpr">bool store keeper role</param>
        /// <param name="subUnitClrk">bool subunit clerk role</param>
        /// <param name="ceo">bool ceo role</param>
        /// <param name="accounting">bool accounting role</param>
        /// <param name="procurement">bool procurement role</param>
        /// <param name="statusId">int statusID</param>
        /// <param name="sessionId">string sessionID</param>
        public User(int uId = 0, string uName = null, string fName = null, string lName = null, string pswd = null, string pswdHint = null, string email = null, bool admin = false, bool genMgr = false, bool storeMgr = false, bool storeKpr = false, bool subUnitClrk = false, bool ceo = false, bool accounting = false, bool procurement = false, int statusID = 1, string sessionID = null)
        {
            userId = uId;
            userName = uName;
            firstName = fName;
            lastName = lName;
            password = pswd;
            passwordHint = pswdHint;
            this.email = email;
            isAdmin = admin;
            isGeneralManager = genMgr;
            isStoreManager = storeMgr;
            isStoreKeeper = storeKpr;
            isSubUnitClerk = subUnitClrk;
            isCEO = ceo;
            isAccounting = accounting;
            isProcurement = procurement;
            statusId = statusID;
            sessionId = sessionID;
        }
        #endregion

        #region getters and setters
        /// <summary>
        /// Gets the user's user ID
        /// </summary>
        /// <returns>int - this user's user ID</returns>
        public int getUserId()
        {
            return userId;
        }
        /// <summary>
        /// Gets the user's current username
        /// </summary>
        /// <returns>string - this user's current username</returns>
        public string getUserName()
        {
            return userName;
        }
        /// <summary>
        /// Gets the user's first name
        /// </summary>
        /// <returns>string - this user's first name</returns>
        public string getFirstName()
        {
            return firstName;
        }
        /// <summary>
        /// Gets the user's last name
        /// </summary>
        /// <returns>string - this user's last name</returns>
        public string getLastName()
        {
            return lastName;
        }
        /// <summary>
        /// Gets the user's current password
        /// </summary>
        /// <returns>string - this user's current password</returns>
        public string getPassword()
        {
            return password;
        }
        /// <summary>
        /// Gets the user's password hint
        /// </summary>
        /// <returns>string - this user's password hint</returns>
        public string getPasswordHint()
        {
            return passwordHint;
        }
        /// <summary>
        /// Gets the user's email address
        /// </summary>
        /// <returns>string - this user's current email address</returns>
        public string getEmail()
        {
            return email;
        }
        /// <summary>
        /// Gets the user's admin permission
        /// </summary>
        /// <returns>bool - true if user has admin privileges, false otherwise</returns>
        public bool getIsAdmin()
        {
            return isAdmin;
        }
        /// <summary>
        /// Gets the user's general manager permission
        /// </summary>
        /// <returns>bool - true if user has general manager privileges, false otherwise</returns>
        public bool getIsGeneralManager()
        {
            return isGeneralManager;
        }
        /// <summary>
        /// Gets the user's store manger permission
        /// </summary>
        /// <returns>bool - true if user has store manager privileges, false otherwise</returns>
        public bool getIsStoreManager()
        {
            return isStoreManager;
        }
        /// <summary>
        /// Gets the user's store keeper permission
        /// </summary>
        /// <returns>bool - true if user has store keeper privileges, false otherwise</returns>
        public bool getIsStoreKeeper()
        {
            return isStoreKeeper;
        }
        /// <summary>
        /// Gets the user's subunit clerk permission
        /// </summary>
        /// <returns>bool - true if user has subunit clerk privileges, false otherwise</returns>
        public bool getIsSubUnitClerk()
        {
            return isSubUnitClerk;
        }
        /// <summary>
        /// Gets the user's CEO permission
        /// </summary>
        /// <returns>bool - true if user has CEO privileges, false otherwise</returns>
        public bool getIsCEO()
        {
            return isCEO;
        }
        /// <summary>
        /// Gets the user's procurement permission
        /// </summary>
        /// <returns>bool - true if user has procurement privileges, false otherwise</returns>
        public bool getIsProcurement()
        {
            return isProcurement;
        }
        /// <summary>
        /// Gets the user's accounting permission
        /// </summary>
        /// <returns>bool - true if user has accounting privileges, false otherwise</returns>
        public bool getIsAccounting()
        {
            return isAccounting;
        }
        /// <summary>
        /// Gets the user's account status ID
        /// </summary>
        /// <returns>int - this user's current account status ID</returns>
        public int getStatusId()
        {
            return statusId;
        }
        /// <summary>
        /// Gets the user's Session ID
        /// </summary>
        /// <returns>string - this user's current session ID</returns>
        public string getSessionId()
        {
            return sessionId;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public int getStoreId()
        {
            return storeId;
        }
        /// <summary>
        /// Sets this user's user Id
        /// </summary>
        /// <param name="_userId">int - represents the set value for this user's user ID</param>
        public void setUserId(int _userId)
        {
            userId = _userId;
        }
        /// <summary>
        /// Sets this user's log in user name
        /// </summary>
        /// <param name="_userName">string - represents the set value for this user's username</param>
        public void setUserName(string _userName)
        {
            userName = _userName;
        }
        /// <summary>
        /// Sets this user's first name
        /// </summary>
        /// <param name="_firstName">string - represents the set value for this user's first name</param>
        public void setFirstName(string _firstName)
        {
            firstName = _firstName;
        }
        /// <summary>
        /// Sets this user's last name
        /// </summary>
        /// <param name="_lastName">string - represents the set value for this user's last name</param>
        public void setLastName(string _lastName)
        {
            lastName = _lastName;
        }
        /// <summary>
        /// Sets this user's password
        /// </summary>
        /// <param name="_password">string - represents the set value for this user's password</param>
        public void setPassword(string _password)
        {
            password = _password;
        }
        /// <summary>
        /// Sets this user's password hint
        /// </summary>
        /// <param name="_passwordHint">string - represents the set value for this user's password hint</param>
        public void setPasswordHint(string _passwordHint)
        {
            passwordHint = _passwordHint;
        }
        /// <summary>
        /// Sets this user's email
        /// </summary>
        /// <param name="_email">string - represents the set value for this user's email address</param>
        public void setEmail(string _email)
        {
            email = _email;
        }
        /// <summary>
        /// Sets this user's admin permission
        /// </summary>
        /// <param name="_isAdmin">bool - represents the set value for whether a user has admin privileges</param>
        public void setIsAdmin(bool _isAdmin)
        {
            isAdmin = _isAdmin;
        }
        /// <summary>
        /// Sets this user's general manager permission
        /// </summary>
        /// <param name="_isGeneralManager">bool - represents the set value for whether a user has general manager privileges</param>
        public void setIsGeneralManager(bool _isGeneralManager)
        {
            isGeneralManager = _isGeneralManager;
        }
        /// <summary>
        /// Sets this user's store manager permission
        /// </summary>
        /// <param name="_isStoreManager">bool - represents the set value for whether a user has store manager privileges</param>
        public void setIsStoreManager(bool _isStoreManager)
        {
            isStoreManager = _isStoreManager;
        }
        /// <summary>
        /// Sets this user's store keeper permission
        /// </summary>
        /// <param name="_isStoreKeeper">bool - represents the set value for whether a user has store keeper privileges</param>
        public void setIsStoreKeeper(bool _isStoreKeeper)
        {
            isStoreKeeper = _isStoreKeeper;
        }
        /// <summary>
        /// Sets this user's subunit clerk permission
        /// </summary>
        /// <param name="_isSubUnitClerk">bool - represents the set value for whether a user has subunit clerk privileges</param>
        public void setIsSubUnitClerk(bool _isSubUnitClerk)
        {
            isSubUnitClerk = _isSubUnitClerk;
        }
        /// <summary>
        /// Sets this user's CEO permission
        /// </summary>
        /// <param name="_isCEO">bool - represents the set value for whether a user has CEO privileges</param>
        public void setIsCEO(bool _isCEO)
        {
            isCEO = _isCEO;
        }
        /// <summary>
        /// Sets this user's procurement permission
        /// </summary>
        /// <param name="_isProcurement">bool - represents the set value for whether a user has procurement privileges</param>
        public void setIsProcurement(bool _isProcurement)
        {
            isProcurement = _isProcurement;
        }
        /// <summary>
        /// Sets this user's accounting permission
        /// </summary>
        /// <param name="_isAccounting">bool - represents the set value for whether a user has accounting privileges</param>
        public void setIsAccounting(bool _isAccounting)
        {
            isAccounting = _isAccounting;
        }
        /// <summary>
        /// Sets this user's account status ID 
        /// </summary>
        /// <param name="_statusId">int - represents the set value for this user's account status ID</param>
        public void setStatusId(int _statusId)
        {
            statusId = _statusId;
        }
        /// <summary>
        /// Sets this user's session ID
        /// </summary>
        /// <param name="_sessionId">string - represents the set value for this user's session ID</param>
        public void setSessionId(string _sessionId)
        {
            sessionId = _sessionId;
        }

        public void setStoreId(int _storeId)
        {
            storeId = _storeId;
        }
        #endregion

        #region methods
        
        /// <summary>
        /// Method in effect simulates logging out a user.  
        /// All class state variables are cleared out and set to their initial state. 
        /// This prepares the User object for a new user log in session.
        /// </summary>
        public void LogOutUser()
        {
            setUserId(0);
            setUserName(null);
            setFirstName(null);
            setLastName(null);
            setPassword(null);
            setPasswordHint(null);
            setIsAdmin(false);
            setIsGeneralManager(false);
            setIsStoreManager(false);
            setIsStoreKeeper(false);
            setIsSubUnitClerk(false);
            setIsCEO(false);
            setIsAccounting(false);
            setIsProcurement(false);
            setEmail(null);
            setStatusId(0);
            setSessionId(null);
        }

        #endregion

    }
}